<?php

class SiteController extends Controller
{

        public function filters()
        {
                return array(
			array(
                                'lastModifiedExpression'=>array($this,'setLastModified'),
				'CHttpCacheFilter + index',
				'etagSeedExpression'=>array($this,'setEtag')
			),
                        array(
				'COutputCache + index',
				'duration'=>172800,
			)
                );
        }
	public function actionIndex()
	{
		$this->render('index');
	}

	/**
	 * 兼容以前的url， 做永久跳转
	 * @param string $bookFlag
	 * @param string $chapterFlag
	 */
	public function actionGoto($bookFlag, $chapterFlag="")
	{
		if ($chapterFlag=="")
			$this->redirect(array('book/default/index', 'bookFlag'=>$bookFlag), true, 301);
		else
			$this->redirect(array('book/default/chapter', 'bookFlag'=>$bookFlag, 'chapterFlag'=> $chapterFlag), true, 301);
	}
	
	/**
	 * 出错处理
	 */
	public function actionError()
	{

	    if($error=Yii::app()->errorHandler->error)
	    {
	    	if(Yii::app()->request->isAjaxRequest)
	    		echo $error['message'];
	    	else {
	    		if ($error['code']==404) {
	    			$this->redirect('/');
	    		}
	    		else {
	    			$this->render('error', $error);
	    		}
	    	}
	    }
	}

}
